package com.metacube.metaconnect.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.metacube.metaconnect.Service.UserInformationService;
import com.metacube.metaconnect.model.UpdateProfileForm;

public class UpdateProfileAction extends Action {

	/*
	 * updates the information of users
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		UpdateProfileForm updateForm = (UpdateProfileForm) form;

		String date_of_birth = request.getParameter("dob");

		if (date_of_birth == null)
			return mapping.findForward("failure");
		else {
			boolean result = new UserInformationService().Update(updateForm,
					date_of_birth);

			if (result) {
				return mapping.findForward("success");
			} else {
				request.setAttribute("errorInUpdate",
						"Something went Wrong!!!! profile could not be updated");
				return mapping.findForward("failure");
			}

		}
		
	}
}
